package com.chinacoal.hr.levelimpl.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chinacoal.hr.levelapi.client.EmployeeClient;
import com.chinacoal.hr.levelapi.client.response.Result;
import com.chinacoal.hr.levelapi.client.response.ResultGenerator;
import com.chinacoal.hr.levelapi.entity.Employee;
import com.chinacoal.hr.levelimpl.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: YunTao.Li
 * @create: 2019-12-04 17:58
 * @description:
 **/
@RestController
public class EmployeeController implements EmployeeClient{

    @Autowired
    private EmployeeService employeeService;

    /**
     * 查询员工信息列表,带分页
     *
     * @param page    :
     * @param limit   :
     * @param empCode :
     * @param empName :
     * @return : com.chinacoal.hr.levelapi.response.Result
     * @author : YunTao.Li
     * @date : 2019/12/4 2019/12/4
     */
    public Result list(long page,
                       long limit,
                       String empCode,
                       String empName,
                       String orgCode) {
        // 构建查询条件
        Map<String, Object> condition = new HashMap<String, Object>();
        condition.put("page", page);
        condition.put("limit", limit);
        condition.put("empCode", empCode);
        condition.put("empName", empName);
        condition.put("orgCode", orgCode);

        IPage<Employee> empList = null;
        try {
            empList = employeeService.getEmployeeList(condition);
        } catch (Throwable e) {
            return ResultGenerator.genFailedResult(e.getMessage());
        }
        return ResultGenerator.genOkResult(empList);
    }

    /**
     * 模糊查询员工列表(按姓名）
     *
     * @param empName :
     * @return : java.util.List<com.chinacoal.hr.levelimpl.entity.Employee>
     * @author : YunTao.Li
     * @date : 2019/12/11 2019/12/11
     */
    public Result listFuzzy(String empName) {
        List<Employee> empList = null;
        try {
            empList = employeeService.getEmployeeListFuzzyByName(empName);
        } catch (Throwable e) {
            return ResultGenerator.genFailedResult(e.getMessage());
        }
        return ResultGenerator.genOkResult(empList);
    }
}


